<template>
  <div class="banner">
    <el-carousel type="card" style="width: 80vw; margin: 0 auto">
      <el-carousel-item v-for="banner in bannerList" :key="banner.relativeId">
        <router-link
          :to="{ name: 'video', params: { uvid: banner.relativeId } }"
          target="_blank"
          v-if="banner.type === BannerTypeEnum.INNER_VIDEO"
        >
          <div class="img-container">
            <el-image :fit="fit" :src="banner.cover" class="banner-img">
              <div slot="error" class="image-slot">
                <i class="el-icon-picture-outline"></i>
              </div>
            </el-image>
          </div>
          <h3 class="banner-title">{{ banner.title }}</h3>
        </router-link>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>
<script>
import { queryBannerItems } from "@/api/home.js";
export default {
  data() {
    return {
      bannerList: [],
      BannerTypeEnum: {
        EXTERNAL_VIDEO: 0,
        INNER_VIDEO: 1,
        EXTERNAL_AD: 2,
        INNER_AD: 3,
      },
      fit: "fill",
    };
  },
  mounted() {
    this.queryBannerList();
  },
  methods: {
    queryBannerList() {
      // banner需要保存到sessionStorage中，
      queryBannerItems(1, 5).then((res) => {
        this.bannerList = res.data;
      });
    },
  },
};
</script>
<style scoped>
.banner {
  padding: 20px 0;
}
.img-container {
  -moz-box-shadow: 10px -10px 5px #888888 inset;
  box-shadow: 0px -20px 20px black inset;
  width: 100%;
  height: 100%;
}
.banner-img {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: -1;
}
.banner-title {
  position: absolute;
  bottom: 0;
  color: white;
  font-size: 24px;
  margin-left: 10px;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>